﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cofe.Core;
using Cofe.Core.Filter;
using Cofe.Core.Interfaces;
using Cofe.Core.Property;

namespace Cofe.Data.Filter
{
    [Export(typeof(ICofeService))]
    [ServicePriority(ServicePriorityAttribute.DefaultPriority_COFEDB)]
    public class DataFilterFactory : IFilterFactory
    {
        #region Constructor

        #endregion

        #region Methods

        private Dictionary<string, Type> getSupportTypes()
        {
            return new Dictionary<string, Type>()
            {
                { "tags", typeof(TagsEntryFilter) }
            };
        }

        public T Construct<T>(string name, string value)
            where T : IFilter
        {
            if (typeof(T) == typeof(IEntryFilter))
                switch (name)
                {
                    case "tags": return (T)(object)new TagsEntryFilter(value);
                }

            return default(T);
        }

        #endregion

        #region Data

        private IPathParser[] _pathParsers = null;
        private IPropertyDictionary _propertyDictionary = null;

        #endregion

        #region Public Properties

        public Dictionary<string, Type> SupportedFilterTypes
        {
            get { return getSupportTypes(); }
        }

        public IPathParser[] PathParsers
        {
            get { return _pathParsers ?? CofeServices.ServiceLocater.FindAllServices<IPathParser>().ToArray(); }
            set { _pathParsers = value; }
        }
        public IPropertyDictionary PropertyDictionary
        {
            get { return _propertyDictionary ?? CofeServices.ServiceLocater.FindService<IPropertyDictionary>(); }
            set { _propertyDictionary = value; }
        }
        #endregion





    }
}
